﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YJKArch.RoomRoofModule
{
	public partial class RoomsBatchCreationForm : System.Windows.Forms.Form
	{
		public RoomsBatchCreationForm(string viewName, SortedList levels)
		{
			this.InitializeComponent();
			this.m_levels = levels;
			this.clbLevels.Items.Clear();
			for (int i = 0; i < levels.Count; i++)
			{
				Level level = levels.GetByIndex(i) as Level;
				this.clbLevels.Items.Add(level.Name);
				if (level.Name.CompareTo(viewName) == 0)
				{
					this.clbLevels.SetItemChecked(i, true);
				}
			}
		}

		public List<Level> GetSelectLevels()
		{
			List<Level> list = new List<Level>();
			for (int i = 0; i < this.clbLevels.Items.Count; i++)
			{
				if (this.clbLevels.GetItemChecked(i))
				{
					list.Add(this.m_levels.GetByIndex(i) as Level);
				}
			}
			return list;
		}

		private void RoomsBatchCreationForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
		}

		private void btnSelAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.clbLevels.Items.Count; i++)
			{
				this.clbLevels.SetItemChecked(i, true);
			}
		}

		private void btnSelReverse_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.clbLevels.Items.Count; i++)
			{
				this.clbLevels.SetItemChecked(i, !this.clbLevels.GetItemChecked(i));
			}
		}

		private void RoomsBatchCreationForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.GetSelectLevels().Count < 1)
			{
				YJKMessageBox.Show("标高列表不能空选。");
				base.DialogResult = DialogResult.None;
			}
		}

		private SortedList m_levels;
	}
}
